package com.lovo.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.stock.bean.PurdetailBean;
import com.lovo.stock.bean.SadetailBean;
import com.lovo.stock.bean.SaleBean;
import com.lovo.stock.mapper.SadetailMapper;
import com.lovo.stock.service.ISadetailService;
import com.lovo.stock.service.ISaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SadetailServiceImpl extends ServiceImpl<SadetailMapper, SadetailBean> implements ISadetailService {
    @Autowired
    SadetailMapper sadetailMapper;

    @Autowired
    ISaleService saleService;

    @Override
    public List<SadetailBean> querySaDetailBySaleId(int saleId) {
        QueryWrapper q=new QueryWrapper<>();
        q.eq("sadetail_sid",saleId);
        return sadetailMapper.selectList(q);
    }

    @Override
    public void addSaleDetail(SaleBean saleBean) {
        int saleId=saleService.addSale(saleBean);
        //将自动生成的主键赋予即将加入数据库的明细表信息
        for (SadetailBean s:saleBean.getSadetailBeans()
             ) {
            s.setSadetailSid(saleId);
        }
        //将数据库明细表信息填入数据库
        sadetailMapper.addSaleDetail(saleBean.getSadetailBeans());
    }
}
